package com.atcapp.server.controller;

import com.atcapp.server.dao.Stu_ActDAO;
import com.atcapp.server.dao.Tea_ActDAO;
import com.atcapp.server.repository.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JoinactController {
    @Autowired
    private UserStuRepository userStuRepository;
    @Autowired
    private InsertStuActRepository insertStuActRepository;
    @Autowired
    private InsertTeaActRepository insertTeaActRepository;
    @Autowired
    private UserTeaRepository userTeaRepository;
    @Autowired
    private StuActRepository stuActRepository;
    @Autowired
    private TeaActRepository teaActRepository;

     /*
    * 学生活动预约
    * */
    @PostMapping(value = "/StuActjoin")
    public String StuActjoin(@RequestParam("username")String userID,
                                      @RequestParam("actID")Integer actID,
                                      @RequestParam("permission")Integer permission) {
        Stu_ActDAO stu_actDAO = new Stu_ActDAO();
        if(permission==1){
            stu_actDAO.setStuid(userID);
            stu_actDAO.setActid(actID);
            insertStuActRepository.save(stu_actDAO);
            return "200";
        }
        return "error";


    }
     /*
    * 教师活动预约
    * */
     @PostMapping(value = "/TeaActjoin")
     public String TeaActjoin(@RequestParam("username")String userID,
                              @RequestParam("actID")Integer actID,
                              @RequestParam("permission")Integer permission) {
         Tea_ActDAO tea_actDAO = new Tea_ActDAO();
         if(permission==2){
             tea_actDAO.setTeaid(userID);
             tea_actDAO.setActid(actID);
             insertTeaActRepository.save(tea_actDAO);
             return "200";
         }
         return "error";


     }
}
